package com.ktjy.springredis.controller;

import com.ktjy.springredis.entity.Employee;
import com.ktjy.springredis.service.EmployeeService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

/**
 * @return 13141
 * 2025/7/17
 * 09:39
 */
@Controller
public class EmployeeController {
    @Resource
    private EmployeeService employeeService;

    @GetMapping(value = "/employees")
    public String getEmployees(Model model) {
        List<Employee> employeeList = employeeService.findAll();
        model.addAttribute("employeeList", employeeList);
        return "demo/emp/empList";
    }

    @GetMapping(value = "/employee/{id}")
    public String getEmployeeById(@PathVariable("id") Long eId,  Model model) {
        Employee employeeDetail = employeeService.getById(eId);
        model.addAttribute("employeeDetail", employeeDetail);
        return "demo/emp/empDetail";
    }
}
